package com.henry.wirte;


import com.tools.hry.utils.DateUtils;
import com.tools.hry.xls.CreateXlsTool;
import com.tools.hry.xls.create.CreateResult;
import com.tools.hry.xls.create.IWriteCallbackFunction;
import com.tools.hry.xls.create.ParamBean;
import com.tools.hry.xls.create.rule.ExcelStyle;
import org.apache.poi.ss.usermodel.CellStyle;

import java.io.File;
import java.io.FileOutputStream;
import java.math.BigDecimal;
import java.net.URL;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
 * Created by 峥桂 on 2017/1/12.
 */
public class TestWrite {
    public static void main(String agrs[]) throws Exception {
//        System.out.println(TestWrite.class.getResource(""));
//        URL url= TestWrite.class.getResource("/");
//        System.out.println(url.getAuthority());
//        url=Thread.currentThread().getContextClassLoader().getResource("");
//        System.out.println(TestWrite.class.getCanonicalName());
        create();
//        createHeader_Datas();
        System.out.println(DateUtils.parse("2017-07-01 23:51:46"));
    }

    public static void createHeader_Datas() throws Exception {
        String headers[]={"投保企业","保单号","赔案号"};
        List dataList=new ArrayList();
        String[] dataStrs={"1","2"};
        String[] dataStrs1={"3","4"};
        dataList.add(dataStrs);
        dataList.add(dataStrs1);

        ParamBean paramBean=new ParamBean();
        paramBean.setActionName("dsfsf");
        paramBean.setTitleName("活动数据");
        paramBean.setNeedTitle(true);
//        paramBean.setCreateTime(new Date().toLocaleString());
        paramBean.setHeaders(headers);

        paramBean.setDatalist(dataList);
//        paramBean.setSelfTemplatePath("D:\\sourcecode\\mayun-git\\base-tools\\xls-tools\\src\\main\\resources/template.xlsx");
        CreateXlsTool.createXLSFromIO(
                paramBean,new File("D://活动数据1.xlsx"),new IWriteCallbackFunction(){
                    public void onFailure(CreateResult result) {
                        result.getException().printStackTrace();
                    }

                    public void onSuccess(CreateResult result) {

                    }
                }
        );
    }



    public static void create() throws Exception {
        List<ClaimsExcelBean> list=new ArrayList<ClaimsExcelBean>();
        ClaimsExcelBean bean=new ClaimsExcelBean();
        bean.setBillMoney(new BigDecimal(123.9));
        bean.setCode("PSDFASDFASFDASFAS-00001");
        bean.setPaymentCaseCode("85000161096059373");
        bean.setApplyCreateTime(DateUtils.parse("2017-07-01 23:51:46"));
//        bean.setApplyCreateTime(new Date());

        list.add(bean);

        ParamBean paramBean=new ParamBean();
        paramBean.setActionName("dsfsf");
        paramBean.setTitleName("活动数据");
        paramBean.setCreateTime(new Date().toLocaleString());
        paramBean.setDatalist(list);
        paramBean.setNeedTitle(false);
        paramBean.setNeedStyle(true);
        paramBean.setSelfTemplatePath("d://template.xlsx");
        CreateXlsTool.createXLSFromIO(
                paramBean,new File("D://活动数据.xlsx"),new IWriteCallbackFunction(){
                    public void onFailure(CreateResult result) {
                        result.getException().printStackTrace();
                    }

                    public void onSuccess(CreateResult result) {

                    }
                }
        );
   /*     FileOutputStream outputStream=new FileOutputStream("D://create2.xls");
        CreateXlsTool.createXLS(list,outputStream,"create2.xls",new IWriteCallbackFunction(){
            public void onFailure(CreateResult result) {
                result.getException().printStackTrace();
            }

            public void onSuccess(CreateResult result) {

            }
        });
        outputStream.flush();
        outputStream.close();*/
    }

}
